<!-- 品牌管理 -->
<template>
    <div>
        
        <div class="table-page-search-wrapper">
            <a-form layout="inline">
                <a-row :gutter="48">
                     <a-col :md="8" :sm="12">
                        <a-form-item label="手机号">
                            <a-input v-model="phone" allow-clear placeholder="请输入用户手机号" />
                        </a-form-item>
                    </a-col>
                     <a-col :md="8">
                        <a-form-item label="黑名单类型">
                            <a-select v-model="type" placeholder="请选择" allowClear @change="getData">
                                <a-select-option v-for="(item,i) in typeList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="8" :sm="24">
                        <a-form-item >
                            <a-button type="primary" @click="getData()">查询</a-button>
                            <a-button style="margin-left: 20px" icon="plus" @click="add()">新增</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>

        <a-table size="small" rowKey="id" :loading="isload" :columns="columns" :data-source="dataList" @change="handleTableChange" :pagination="{ pageSize: 10, total: total ,showSizeChanger: true,pageSize: size}" >
            <template slot="type" slot-scope="type">
                 <div v-for="(item,i) in typeList" :key="i">
                     <a-tag  v-if="item.id == type" >{{item.name}}</a-tag>  
                </div>
            </template>
            <template slot="operation" slot-scope="text, record">
                
                <div class="editable-row-operations">
                    <a-button type="link" @click="update(record)">修改</a-button>
                    <a-popconfirm
                        title="是否确认删除当前数据?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="del(record)"
                    >
                        <a-button type="link">删除</a-button>
                    </a-popconfirm>
                </div>
            </template>
        </a-table>

        <a-modal
            title="添加、修改黑名单设置"
            :visible="visible"
            @ok="handleOk"
            @cancel="visible = false"
            >
            <div>
                <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 17 }">
                    <a-form-item label="黑名单类型">
                        <a-select v-model="item.type" placeholder="请选择" allowClear>
                            <a-select-option v-for="(item,i) in typeList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                        </a-select>
                    </a-form-item>
                     <a-form-item label="黑名单手机号">
                        <a-input   v-model="item.phone" placeholder="请输入升级推广人数" allow-clear></a-input>
                    </a-form-item>
                   <a-form-item label="备注">
                        <a-textarea v-model="item.remark"   placeholder="请输入加入黑名单备注" allow-clear></a-textarea>
                    </a-form-item>

                </a-form>
            </div>
        </a-modal>
    </div>
</template>

<script>
import { queryBlacklist,updateBlacklist  } from '@/api/member';
import { columns } from './table';
import moment from "moment";
export default {
    data () {
        return {
            brandId: this.global.brandId,
            dataList: [],
            total: 0,
            size: 10,
            page: 1,
            columns,
            isload: false,
            visible: false,
            item: {
                id: '',
                type:1,//黑名单类型,1:登陆黑名单,2:提现黑名单,3:商城购买黑名单,4:拼团黑名单	
                phone:"",
                remark:""
            },
            phone:"",
            type:"",
            typeList: [
                { id: 1, name: '登陆黑名单'},
                { id: 2, name: '提现黑名单'},
                { id: 3, name: '商城购买黑名单'},
            ],

            previewImgVisible: false
        };
    },

    async created(){
        this.getData()
    },
    methods: {
        moment,
        getData(){
            let _this = this
            _this.isload = true
            const params = {
                'brandId':_this.brandId,
                'phone':_this.phone,
                'type':_this.type,
                'size':_this.size,
                'page':_this.page - 1,
            }
            queryBlacklist(params)
            .then(res=>{
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data.content
                    _this.total = res.data.totalElements
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
        // 添加
        add(){

            this.item={
                 id: '',
                type:1,//黑名单类型,1:登陆黑名单,2:提现黑名单,3:商城购买黑名单,4:拼团黑名单	
                phone:"",
                remark:""
            },
            this.visible = true
        },
        // 修改
        update(item){
            this.item = JSON.parse(JSON.stringify(item))
          this.visible = true
          
        },
        // 确定添加、删除
        handleOk(){
          
            let _this = this
            const params = {
                'id':_this.item.id,
                'brandId':_this.brandId,
                'phone':_this.item.phone,
                'type':_this.item.type,
                'remark':_this.item.remark,
            }
            console.log(params)
            
            if(!this.brandId){
                this.$message.warning('请先选择品牌!')
                return
            }
            if(!_this.item.phone){
                this.$message.warning('请先输入手机号!')
                return
            }
             if(!_this.item.type){
                this.$message.warning('请先选择黑名单类型!')
                return
            }
           
             if(!_this.item.remark){
                this.$message.warning('请先输入备注!')
                return
            }
            updateBlacklist(params)
            .then(res=>{
                if(res.success){
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: _this.item.id ? '修改成功' : '添加成功',
                        duration: 8,
                    })
                    _this.visible = false
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 删除
        del(item){
            let _this = this
            const params = {
                'id':item.id,
                'isDelete':1,
            }
            updateBlacklist(params)
            .then(res=>{
                if(res.success){
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: '删除成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
    }
}

</script>
<style scoped>

</style>